<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Web SSH 企业版客户端</title>
    <!-- 引入xterm.js -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/xterm@5.3.0/css/xterm.css" />
    <script src="https://cdn.jsdelivr.net/npm/xterm@5.3.0/lib/xterm.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/xterm-addon-fit@0.8.0/lib/xterm-addon-fit.js"></script>
    <!-- 引入Font Awesome图标 -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@6.4.0/css/all.min.css">
    
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            background: #f5f7fa;
            color: #333;
        }
        
        .main-container {
            display: flex;
            height: 100vh;
        }
        
        /* 侧边栏样式 */
        .sidebar {
            width: 320px;
            background: #fff;
            border-right: 1px solid #e1e8ed;
            overflow-y: auto;
            transition: width 0.3s ease;
        }
        
        .sidebar.collapsed {
            width: 60px;
        }
        
        .sidebar-header {
            padding: 20px;
            border-bottom: 1px solid #e1e8ed;
            display: flex;
            align-items: center;
            justify-content: space-between;
        }
        
        .sidebar-title {
            font-size: 18px;
            font-weight: 600;
            color: #1da1f2;
        }
        
        .sidebar-toggle {
            background: none;
            border: none;
            font-size: 16px;
            cursor: pointer;
            padding: 5px;
            border-radius: 4px;
        }
        
        .sidebar-toggle:hover {
            background: #f0f0f0;
        }
        
        .sidebar-nav {
            padding: 10px 0;
        }
        
        .nav-item {
            padding: 12px 20px;
            cursor: pointer;
            display: flex;
            align-items: center;
            gap: 12px;
            transition: background-color 0.2s;
            border-left: 3px solid transparent;
        }
        
        .nav-item:hover {
            background: #f8f9fa;
        }
        
        .nav-item.active {
            background: #e3f2fd;
            border-left-color: #1da1f2;
            color: #1da1f2;
        }
        
        .nav-icon {
            width: 18px;
            text-align: center;
        }
        
        /* 主内容区样式 */
        .main-content {
            flex: 1;
            padding: 20px;
            overflow-y: auto;
        }
        
        .content-header {
            background: #fff;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
            margin-bottom: 20px;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        
        .content-title {
            font-size: 24px;
            font-weight: 600;
            color: #333;
        }
        
        .action-buttons {
            display: flex;
            gap: 10px;
        }
        
        /* 页面内容样式 */
        .page-content {
            display: none;
        }
        
        .page-content.active {
            display: block;
        }
        
        /* SSH连接页面样式 */
        .connection-panel {
            background: #fff;
            padding: 25px;
            border-radius: 8px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
            margin-bottom: 20px;
        }
        
        .connection-form {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
            gap: 20px;
            margin-bottom: 20px;
        }
        
        .form-group {
            display: flex;
            flex-direction: column;
        }
        
        .form-group label {
            margin-bottom: 8px;
            font-weight: 500;
            color: #333;
        }
        
        .form-group input, .form-group select {
            padding: 12px;
            border: 1px solid #ddd;
            border-radius: 6px;
            font-size: 14px;
            transition: border-color 0.2s;
        }
        
        .form-group input:focus, .form-group select:focus {
            outline: none;
            border-color: #1da1f2;
            box-shadow: 0 0 0 3px rgba(29, 161, 242, 0.1);
        }
        
        .checkbox-group {
            display: flex;
            align-items: center;
            gap: 8px;
            margin-top: 15px;
        }
        
        .checkbox-group input[type="checkbox"] {
            width: auto;
        }
        
        /* 按钮样式 */
        .btn {
            padding: 12px 24px;
            border: none;
            border-radius: 6px;
            cursor: pointer;
            font-size: 14px;
            font-weight: 500;
            transition: all 0.2s;
            display: inline-flex;
            align-items: center;
            gap: 8px;
            text-decoration: none;
        }
        
        .btn-primary {
            background: #1da1f2;
            color: white;
        }
        
        .btn-primary:hover {
            background: #1991db;
            transform: translateY(-1px);
        }
        
        .btn-success {
            background: #17a2b8;
            color: white;
        }
        
        .btn-success:hover {
            background: #138496;
        }
        
        .btn-danger {
            background: #dc3545;
            color: white;
        }
        
        .btn-danger:hover {
            background: #c82333;
        }
        
        .btn-secondary {
            background: #6c757d;
            color: white;
        }
        
        .btn-secondary:hover {
            background: #545b62;
        }
        
        .btn:disabled {
            opacity: 0.6;
            cursor: not-allowed;
            transform: none;
        }
        
        /* 终端样式 */
        .terminal-container {
            background: #fff;
            border-radius: 8px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
            overflow: hidden;
            margin-bottom: 20px;
            display: flex;
            flex-direction: column;
            height: 600px;
        }
        
        /* Terminal Tab样式 */
        .terminal-tabs {
            display: flex;
            background: #f8f9fa;
            border-bottom: 1px solid #dee2e6;
            overflow-x: auto;
            min-height: 40px;
        }
        
        .terminal-tab {
            display: flex;
            align-items: center;
            padding: 8px 16px;
            background: #f8f9fa;
            border: none;
            border-right: 1px solid #dee2e6;
            cursor: pointer;
            font-size: 14px;
            white-space: nowrap;
            min-width: 120px;
            max-width: 200px;
            position: relative;
        }
        
        .terminal-tab.active {
            background: #fff;
            border-bottom: 2px solid #1da1f2;
        }
        
        .terminal-tab:hover {
            background: #e9ecef;
        }
        
        .terminal-tab.active:hover {
            background: #fff;
        }
        
        .tab-title {
            flex: 1;
            text-overflow: ellipsis;
            overflow: hidden;
            margin-right: 8px;
        }
        
        .tab-status {
            width: 8px;
            height: 8px;
            border-radius: 50%;
            margin-right: 8px;
        }
        
        .tab-status.connected {
            background: #28a745;
        }
        
        .tab-status.disconnected {
            background: #dc3545;
        }
        
        .tab-actions {
            display: flex;
            gap: 4px;
        }
        
        .tab-btn {
            background: none;
            border: none;
            padding: 2px 4px;
            border-radius: 3px;
            cursor: pointer;
            font-size: 12px;
            color: #666;
        }
        
        .tab-btn:hover {
            background: rgba(0,0,0,0.1);
            color: #333;
        }
        
        .terminal-content {
            flex: 1;
            position: relative;
            overflow: hidden;
        }
        
        .terminal-session {
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            display: none;
            flex-direction: column;
        }
        
        .terminal-session.active {
            display: flex;
        }
        
        .terminal-header {
            background: #2d3748;
            color: white;
            padding: 10px 15px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            min-height: 40px;
        }
        
        .terminal-info {
            display: flex;
            align-items: center;
            gap: 15px;
        }
        
        .connection-status {
            font-size: 13px;
            font-weight: 500;
            display: flex;
            align-items: center;
            gap: 6px;
        }
        
        .terminal-actions {
            display: flex;
            gap: 8px;
        }
        
        .terminal-btn {
            background: rgba(255,255,255,0.1);
            border: none;
            color: white;
            padding: 6px 10px;
            border-radius: 4px;
            cursor: pointer;
            font-size: 11px;
            transition: background-color 0.2s;
        }
        
        .terminal-btn:hover {
            background: rgba(255,255,255,0.2);
        }
        
        .terminal-wrapper {
            flex: 1;
            padding: 10px;
            background: #1e1e1e;
        }
        
        .status-bar {
            background: #f8f9fa;
            padding: 10px 20px;
            border-top: 1px solid #dee2e6;
            font-size: 12px;
            color: #6c757d;
            display: flex;
            justify-content: space-between;
        }
        
        /* 服务器分组管理样式 */
        .groups-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
            gap: 20px;
            margin-bottom: 20px;
        }
        
        .group-card {
            background: #fff;
            border-radius: 8px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
            padding: 20px;
            transition: transform 0.2s;
        }
        
        .group-card:hover {
            transform: translateY(-2px);
        }
        
        .group-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 15px;
        }
        
        .group-name {
            font-size: 18px;
            font-weight: 600;
            color: #333;
        }
        
        .group-actions {
            display: flex;
            gap: 8px;
        }
        
        .group-actions .btn {
            padding: 6px 12px;
            font-size: 12px;
        }
        
        .group-description {
            color: #666;
            margin-bottom: 15px;
            font-size: 14px;
        }
        
        .server-list {
            list-style: none;
        }
        
        .server-item {
            padding: 8px 0;
            border-bottom: 1px solid #f0f0f0;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        
        .server-item:last-child {
            border-bottom: none;
        }
        
        .server-info {
            flex: 1;
        }
        
        .server-name {
            font-weight: 500;
            color: #333;
        }
        
        .server-address {
            font-size: 12px;
            color: #666;
        }
        
        /* 文件管理器样式 */
        .file-manager {
            background: #fff;
            border-radius: 8px;
            box-shadow: 0 2px 8px rgba(0,0,0,0.1);
            overflow: hidden;
        }
        
        .file-manager-header {
            padding: 20px;
            border-bottom: 1px solid #e1e8ed;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        
        .file-path {
            display: flex;
            align-items: center;
            gap: 10px;
            flex: 1;
        }
        
        .file-path input {
            flex: 1;
            padding: 8px 12px;
            border: 1px solid #ddd;
            border-radius: 4px;
            font-family: monospace;
        }
        
        .file-actions {
            display: flex;
            gap: 10px;
        }
        
        .file-grid {
            padding: 20px;
        }
        
        .file-item {
            display: flex;
            align-items: center;
            padding: 12px;
            border-radius: 6px;
            cursor: pointer;
            transition: background-color 0.2s;
        }
        
        .file-item:hover {
            background: #f8f9fa;
        }
        
        .file-icon {
            width: 24px;
            margin-right: 12px;
            color: #666;
        }
        
        .file-name {
            flex: 1;
            font-weight: 500;
        }
        
        .file-size {
            color: #666;
            font-size: 12px;
            margin-right: 15px;
        }
        
        .file-date {
            color: #666;
            font-size: 12px;
            margin-right: 15px;
        }
        
        /* 弹窗样式 */
        .modal {
            display: none;
            position: fixed;
            z-index: 1000;
            left: 0;
            top: 0;
            width: 100%;
            height: 100%;
            background: rgba(0,0,0,0.5);
        }
        
        .modal.active {
            display: flex;
            align-items: center;
            justify-content: center;
        }
        
        .modal-content {
            background: #fff;
            border-radius: 8px;
            padding: 30px;
            max-width: 500px;
            width: 90%;
            max-height: 80vh;
            overflow-y: auto;
        }
        
        .modal-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 20px;
        }
        
        .modal-title {
            font-size: 20px;
            font-weight: 600;
        }
        
        .modal-close {
            background: none;
            border: none;
            font-size: 24px;
            cursor: pointer;
            color: #666;
        }
        
        .modal-close:hover {
            color: #333;
        }
        
        /* 提示框样式 */
        .alert {
            padding: 12px 16px;
            margin-bottom: 20px;
            border: 1px solid transparent;
            border-radius: 6px;
            font-size: 14px;
        }
        
        .alert-success {
            color: #155724;
            background-color: #d4edda;
            border-color: #c3e6cb;
        }
        
        .alert-danger {
            color: #721c24;
            background-color: #f8d7da;
            border-color: #f5c6cb;
        }
        
        .alert-info {
            color: #0c5460;
            background-color: #d1ecf1;
            border-color: #bee5eb;
        }
        
        /* 隐藏样式 */
        .hidden {
            display: none !important;
        }
        
        /* 加载动画 */
        .loading {
            display: inline-block;
            width: 20px;
            height: 20px;
            border: 3px solid rgba(255,255,255,.3);
            border-radius: 50%;
            border-top-color: #fff;
            animation: spin 1s ease-in-out infinite;
        }
        
        @keyframes spin {
            to { transform: rotate(360deg); }
        }
        
        /* 响应式设计 */
        @media (max-width: 768px) {
            .main-container {
                flex-direction: column;
            }
            
            .sidebar {
                width: 100%;
                height: auto;
                border-right: none;
                border-bottom: 1px solid #e1e8ed;
            }
            
            .connection-form {
                grid-template-columns: 1fr;
            }
        }
    </style>
</head>
<body>
    <div class="main-container">
        <!-- 侧边栏 -->
        <div class="sidebar" id="sidebar">
            <div class="sidebar-header">
                <div class="sidebar-title">
                    <i class="fas fa-terminal"></i>
                    <span id="sidebarTitle">Web SSH</span>
                </div>
                <button class="sidebar-toggle" onclick="toggleSidebar()">
                    <i class="fas fa-bars"></i>
                </button>
            </div>
            
            <nav class="sidebar-nav">
                <div class="nav-item active" onclick="switchPage('ssh')">
                    <i class="fas fa-terminal nav-icon"></i>
                    <span class="nav-text">SSH连接</span>
                </div>
                <div class="nav-item" onclick="switchPage('files')">
                    <i class="fas fa-folder nav-icon"></i>
                    <span class="nav-text">文件管理</span>
                </div>
            </nav>
        </div>
        
        <!-- 主内容区 -->
        <div class="main-content">
            <!-- SSH连接页面 -->
            <div class="page-content active" id="page-ssh">
                <div class="content-header">
                    <h1 class="content-title">SSH连接管理</h1>
                    <div class="action-buttons">
                        <button class="btn btn-secondary" onclick="loadSavedServers()">
                            <i class="fas fa-download"></i> 加载保存的服务器
                        </button>
                    </div>
                </div>
                
                <!-- 连接面板 -->
                <div class="connection-panel">
                    <div class="connection-form">
                        <div class="form-group">
                            <label for="savedServers">快速连接</label>
                            <select id="savedServers" onchange="loadServerConfig()">
                                <option value="">选择已保存的服务器...</option>
                            </select>
                        </div>
                        <div class="form-group">
                            <label for="host">服务器地址</label>
                            <input type="text" id="host" placeholder="192.168.1.100 或 example.com" value="localhost">
                        </div>
                        <div class="form-group">
                            <label for="port">端口</label>
                            <input type="number" id="port" placeholder="22" value="22">
                        </div>
                        <div class="form-group">
                            <label for="username">用户名</label>
                            <input type="text" id="username" placeholder="root">
                        </div>
                        <div class="form-group">
                            <label for="password">密码</label>
                            <input type="password" id="password" placeholder="密码">
                        </div>
                        <div class="form-group">
                            <label for="serverName">服务器名称（可选）</label>
                            <input type="text" id="serverName" placeholder="给这个连接起个名字">
                        </div>
                    </div>
                    
                    
                    <div class="checkbox-group">
                        <input type="checkbox" id="saveServer">
                        <label for="saveServer">保存此服务器配置</label>
                    </div>
                    
                    <div style="margin-top: 20px; display: flex; gap: 10px;">
                        <button class="btn btn-primary" onclick="connectSSH()">
                            <i class="fas fa-plug"></i> 连接
                        </button>
                        <button class="btn btn-success" onclick="testConnection()" id="testBtn">
                            <i class="fas fa-check"></i> 测试连接
                        </button>
                        <button class="btn btn-danger" onclick="disconnectSSH()" disabled id="disconnectBtn">
                            <i class="fas fa-times"></i> 断开连接
                        </button>
                    </div>
                    
                    <!-- 状态提示 -->
                    <div id="alertContainer"></div>
                </div>
                
                <!-- 终端容器 -->
                <div class="terminal-container hidden" id="terminalContainer">
                    <!-- Tab栏 -->
                    <div class="terminal-tabs" id="terminalTabs">
                        <!-- tabs will be added dynamically -->
                    </div>
                    
                    <!-- Terminal内容区 -->
                    <div class="terminal-content" id="terminalContent">
                        <!-- terminals will be added dynamically -->
                    </div>
                    
                    <div class="status-bar">
                        <span id="statusBar">就绪</span>
                        <span id="terminalStats">行: 24, 列: 80</span>
                    </div>
                </div>
            </div>
            
            <!-- 文件管理页面 -->
            <div class="page-content" id="page-files">
                <div class="content-header">
                    <h1 class="content-title">文件管理器</h1>
                    <div class="action-buttons">
                        <button class="btn btn-primary" onclick="showUploadModal()">
                            <i class="fas fa-upload"></i> 上传文件
                        </button>
                        <button class="btn btn-success" onclick="createFolder()">
                            <i class="fas fa-folder-plus"></i> 新建文件夹
                        </button>
                    </div>
                </div>
                
                <div class="file-manager" id="fileManager">
                    <div class="file-manager-header">
                        <div class="file-path">
                            <button class="btn btn-secondary" onclick="navigateUp()">
                                <i class="fas fa-arrow-up"></i>
                            </button>
                            <input type="text" id="currentPath" value="/" readonly>
                            <button class="btn btn-secondary" onclick="refreshFiles()">
                                <i class="fas fa-sync"></i>
                            </button>
                        </div>
                        <div class="file-actions">
                            <select id="fileServerSelect" onchange="switchFileServer()" style="padding: 8px 12px; border: 1px solid #ddd; border-radius: 4px; background: white;">
                                <option value="">选择服务器...</option>
                            </select>
                        </div>
                    </div>
                    <div class="file-grid" id="fileGrid">
                        <div class="alert alert-info">
                            请先选择一个服务器来浏览文件
                        </div>
                    </div>
                </div>
            </div>
            
        </div>
    </div>
    
    <!-- 弹窗 -->
    <!-- 文件上传弹窗 -->
    <div class="modal" id="uploadModal">
        <div class="modal-content">
            <div class="modal-header">
                <h3 class="modal-title">上传文件</h3>
                <button class="modal-close" onclick="closeModal('uploadModal')">&times;</button>
            </div>
            <div>
                <div class="form-group">
                    <label for="uploadFiles">选择文件</label>
                    <input type="file" id="uploadFiles" multiple>
                </div>
                <div class="form-group">
                    <label for="uploadPath">上传路径</label>
                    <input type="text" id="uploadPath" value="/" required>
                </div>
                <div style="text-align: right; margin-top: 20px;">
                    <button type="button" class="btn btn-secondary" onclick="closeModal('uploadModal')">取消</button>
                    <button type="button" class="btn btn-primary" onclick="handleUpload(); return false;">上传</button>
                </div>
            </div>
        </div>
    </div>
    

    <!-- JavaScript代码 -->
    <script src="js/webssh-multisession.js"></script>
</body>
</html>